<?php

include 'init.php';

$admin = new Admin();
$admin->checkAdmin();

if ($_GET['act']=="list_admin") {
    $s = new SettingsAdmin;
    $data['list'] = Array();
    $data['title'] = 'Редактирование администраторов';
    $query = $s->getAllAdmins();
    foreach($query as $id=>$row)
    {
        $data['list'][$id]['id'] = $row['id'];
        $data['list'][$id]['name'] = $row['nickname'];
    }
    $tpl = new TemplateAdmin('settings_admin_list', $data);
    $tpl->viewTemplate();
    
} else {
    $s = new SettingsAdmin;
    $data['list'] = Array();
    $data['title'] = 'Настройки сайта';
    $result = $s->getAllSetting();
    foreach ($result as $id => $row) {
        $data['list'][$id]['id'] = $row['id'];
        $data['list'][$id]['name'] = $row['key'];
        $values = unserialize($row['value']);
        if (is_array($values)) {
            $data['list'][$id]['settings'] .= '<ul>';
            foreach ($values as $key => $value) {
                $data['list'][$id]['settings'] .= '<li>' . $key . ' => ' . $value . '</li>';
            }
            $data['list'][$id]['settings'] .= '</ul>';
        } else {
            $data['list'][$id]['settings'] = $row['value'];
        }
    }

    $tpl = new TemplateAdmin('settings_all', $data);
    $tpl->viewTemplate();
}
?>
